package com.xy.lang.util;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class StringUtilsEx {

    public static String captureName(String name) {
        if(null == name || name.length() == 0) {
            return name;
        }
        if(name.length() == 1) {
            return name.toUpperCase();
        }
        return name.substring(0, 1).toUpperCase() + name.substring(1);
    }

    public static String toBase64(String value) {
        return Base64.getEncoder().encodeToString(value.getBytes(StandardCharsets.UTF_8));
    }

    public static String fromBase64(String value) {
        return new String(Base64.getDecoder().decode(value), StandardCharsets.UTF_8);
    }


    /// tests

    public static void main(String[] args) {
        String value = "Hello World! 嗨，您好！";
        String encodingString = toBase64(value);
        System.out.println(encodingString);
        String decodingString = fromBase64(encodingString);
        System.out.println(decodingString);
    }

}
